package com.itheima.web.controller;

import com.itheima.pojo.KsClass;
import com.itheima.pojo.LoginDto;
import com.itheima.pojo.User;
import com.itheima.service.LoginService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/v1/login")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @GetMapping("/{mobile}")
    public ResponseResult findPosition(@PathVariable String mobile){
        return loginService.findPosition(mobile);
    }
    @PostMapping("/in")
    public ResponseResult login(HttpServletRequest request, @RequestBody LoginDto loginDto){
        User user = loginService.login(loginDto);
        if (user != null){
            //把班级id放进Session
            request.getSession().setAttribute("ClassId",loginDto.getClassId());
            return new ResponseResult<>(0,"操作成功",user);
        }
        return new ResponseResult<>(1,"操作失败",null);
    }


}